#define _CRT_SECURE_NO_WARNINGS 1

#include "list.h"
#include <list>

#include <string>
#include <algorithm>

//int main()
//{
//	ljl::list_test8();
//	/*list<int> lt;
//	lt.push_back(1);
//
//	cout << lt.back() << endl;
//	cout << lt.front() << endl;*/
//	return 0;
//}

class Solution {
public:

    string addStrings(string num1, string num2)
    {
        int end1 = num1.size() - 1, end2 = num2.size() - 1;
        int carry = 0;
        string retStr;
        while (end1 >= 0 || end2 >= 0)
        {
            int val1 = end1 >= 0 ? num1[end1] - '0' : 0;
            int val2 = end2 >= 0 ? num2[end2] - '0' : 0;

            int ret = val1 + val2 + carry;
            carry = ret / 10;
            retStr += (ret % 10) + '0';

            end1--;
            end2--;
        }
        if (carry == 1)
        {
            retStr += '1';
        }
        reverse(retStr.begin(), retStr.end());
        return retStr;
    }

    string multiply(string num1, string num2) {
        int n1 = 0;
        int n = 0;
        string s = "0";
        string _retStr = "";
        string _rs;
        auto it1 = num1.rbegin();
        int factor1 = 1;
        int s1 = num1.size() - 1, s2 = num2.size() - 1;
        int factor2 = 0;
        int i = 0, j = 0;
        while (s2 >= 0)
        {
            while (it1 != num1.rend())
            {
                n1 += ((*it1) - '0') * factor1;
                ++it1;
                factor1 *= 10;
            }
            n = n1 * (num2[s2] - '0');
            _retStr = "";
            while (n)
            {
                _retStr += (n % 10) + '0';
                n /= 10;
            }
            reverse(_retStr.begin(), _retStr.end());
            int i = j;
            while (i)
            {
                _retStr += "0";
                i--;
            }
            _rs = addStrings(_retStr, s);
            s = _rs;
            --s2;
            j++;
        }
        return _rs;
    }
};

int main()
{
    Solution s;
    cout << s.multiply("123", "456") << endl;
    return 0;
}